package com.example.test.责任连;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author hzj@jovision.com
 * @Date 2020/12/5 下午12:01
 * @Description TODO
 */
@Service
public class EventSourceServiceImpl {
    @Autowired
    SourceHandlerFactory handlerFactory;

    public boolean trigger() {
        // 根据类型从工厂类找到事件源执行类
        AbstractSourceHandler sourceHandler = handlerFactory.getHandler("1");
        // 创建事件源执行职责链
        SourceHandlerChain handlerChain = new SourceHandlerChain();
        handlerChain.addHandler(sourceHandler);
        // 添加事件发生条件执行逻辑
        handlerChain.addHandler(handlerFactory.getHandler("2"));
        // 添加事件规则执行逻辑
        handlerChain.addHandler(handlerFactory.getHandler("3"));
        handlerChain.handle();
        return true;
    }
}
